<?php 
$start = 0;
$offset = 20;
?>
<script type="text/javascript">
var limit = {
		start : parseInt(0)	
}

function failure(message){
	box_failure = new LightFace({ 
			title: 'Failure', 
			width : 300,
			content: "<div class='failure'>"+message+"</div>"
			,
			buttons: [{ title: 'Cancel', event: function() { this.close();}, color: 'green'}]
		});
		box_failure.open();		
}
function box_message(titleMessage,message){
	box_message = new LightFace({ 
			title: titleMessage, 
			width : 300,
			content: "<div class='message'>"+message+"</div>"
			,
			buttons: [{ title: 'Close', event: function() { this.close();}, color: 'green'}]
		});
		box_message.open();
}

function addsub(id){
	//alert(id);
	box_sub = new LightFace.Request({
		width:450,
		height:210,
		url:'<?php echo site_url('dash/ajax_subject_add')?>',
		buttons: [
			{ title: 'Cancel', event: function() { this.close(); } },
			{ title: 'Save', event: function() {saveSubject(this, event, id), subjectShow(id)}, color: 'blue' }
		],
		title: 'Add Subject'
	}).open();

	//saveSubject(this, event, id); 

}

function saveSubject(form, evt, id) {
	//alert(id);
	
	new Event(evt).stop();
	form = $(form);
		form.set('send', {url:'<?php echo site_url('dash/ajax_subject_save')?>'+'/'+id, method:'post',
				 	onSuccess: function(responseText, responseXML){
						box_sub.close();
						showSubject(id);
					},
					onComplete: function(){
						
					},
					onFailure: function(xhr){
						var message = "Failed to save";
						failure(message);
					}
				});
		form.send();
}

function subjectShow() {
	//alert("oke");
	var name 		= $(document.forms['formaddsubject']).name.value;
	var format 		= $(document.forms['formaddsubject']).format.value;
	var time		= $(document.forms['formaddsubject']).time.value;
	var description	= $(document.forms['formaddsubject']).description.value;
	var author		= $(document.forms['formaddsubject']).author.value;
	//alert(description);
	var tr = new Element('tr');
	var td1 = new Element('td')
		.set('class','font-size-16 capitalize')
		.set('align','left');
	var a = new Element('a')
		.set('href','<?php echo base_url();?>dash/quiz/<?php echo $this->uri->segment(3,0)?>/'+name+'/open');
	var div = new Element('div').set('html',name);
	var divf = new Element('div')
		.set('class','font-size-10 font-color-gray untransform italic')
		.set('html',"type : "+format);
	var diva = new Element('div')
		.set('class','font-size-10 font-color-gray untransform italic')
		.set('html',"posted by "+ author);
	var td2 = new Element('td')
		.set('class','font-size-16 bold padding-right-20')
		.set('width','15%')
		.set('align','right');
	var span = new Element('span').set('class','italic').set('html','edit');
	var spanx = new Element('span').set('class','margin-left-20 italic').set('html','x');
	
	
	var tr2 = new Element('tr');
	var td3 = new Element('td').set('colspan',2);
	var hr = new Element('hr')
		.set('size',1)
		.set('width','98%')
		.set('color','#cccccc')
		.set('align','left');
	//tr.adopt(td1).adopt(a).adopt(div).adopt(divf).adopt(diva);
	//tr2.wraps(td2).wraps(hr);
	tr.adopt(td1);
	td1.adopt(a);
	a.adopt(div);
	div.adopt(divf).grab(diva);
	tr.adopt(td2);
	td2.adopt(span);
	span.adopt(spanx);

	tr2.adopt(td3);
	td3.adopt(hr);
	
	$('addshowsubject').grab(tr).grab(tr2);
	tr.fade('hide');
	tr.fade(1);
	tr2.fade('hide');
	tr2.fade(1);

	box_sub.close();
}

function addlesson(){
	box_lesson = new LightFace.Request({
		width:300,
		height:40,
		url:'<?php echo site_url('dash/ajax_lesson_add')?>',
		buttons: [
			{ title: 'Cancel', event: function() { this.close(); } },
			{ title: 'Save', event: function() { saveLesson(this, event); }, color: 'blue' }
		],
		title: 'Add Lesson'
	}).open();

}


function saveLesson(form, evt){
	new Event(evt).stop();
	form = $(form);
//	alert($(document.forms[0]).name.value);
		form.set('send', {url:'<?php echo site_url('dash/ajax_lesson_save')?>', method:'post',
				 	onSuccess: function(responseText, responseXML){
						box_lesson.close();
						showLesson();
					},
					onComplete: function(){
						
					},
					onFailure: function(xhr){
						var message = "Failed to save";
						failure(message);
					}
				});
		form.send();
}

function showLesson(){
	var temp = {
		src : $(document.forms['search']).src.value
		
	}
	var perpage = {
		page : parseInt($(document.forms['viewperpage']).perpage.value)
	}
	
	
	var myRequest = new Request({
		url: '<?php echo base_url()."dash/lesson_show/"?>'+limit.start+'/'+perpage.page+'/'+temp.src,
		method: 'post',
		onSuccess : function(responseText){
			$('lesson_show').fade('hide');
			$('lesson_show').fade(1);
			//$('lesson_show').set('tween', {transition: Fx.Transitions.Elastic.easeIn});
			$('lesson_show').innerHTML = responseText;
		}
	}).send();

}

function showQue(){
	var myRequest = new Request({
		url: '<?php echo base_url()."dash/ajax_que_show/"?><?php echo $this->uri->segment(3,0)?>',
		method: 'post',
		onSuccess : function(responseText){
			$('showque').fade('hide');
			$('showque').fade(1);
			//$('showque').set('tween', {transition: Fx.Transitions.Elastic.easeIn});
			$('showque').innerHTML = responseText;
		}
	}).send();

}


function showSubject(id){
	var temp = {
		src : $(document.forms['search']).src.value
		
	}
	var perpage = {
		page : parseInt($(document.forms['viewperpage']).perpage.value)
	}
	
	
	var myRequest = new Request({
		url: '<?php echo base_url()."dash/subject_show/"?>'+limit.start+'/'+perpage.page+'/'+id+'/'+temp.src,
		method: 'post',
		onSuccess : function(responseText){
			$('subject_show').fade('hide');
			$('subject_show').fade(1);
			//$('subject_show').set('tween', {transition: Fx.Transitions.Elastic.easeIn});
			$('subject_show').innerHTML = responseText;
			setButSubject();
		}
	}).send();

}

function setButSubject() {
	//alert('<?php echo get_cookie('subject')?>');
	var id = '<?php echo get_cookie('subject')?>'
	$('butaddsubject')
		.set('html','add')
		.set('href',"javascript: addsubject('<?php echo get_cookie('subject')?>')")
		.set('class','uiButtonRounded bold font-size-11')
		.set('title','add');
}

function cekSubject() {
	//alert('<?php echo get_cookie('subject')?>');
}

function addsubject(id) {
	//var id = '<?php echo get_cookie('subject')?>';
	//alert(id);
}

function search_pages(form, evt){
	var perpage = {
			page : parseInt($(document.forms['viewperpage']).perpage.value)
		}
	new Event(evt).stop();
	var temp = {
		src : $(document.forms['search']).src.value
	}
	form = $(form);
		form.set('send', {
			url:'<?php echo site_url(array('dash','lesson_show')) ?>'+'/'+limit.start+'/'+perpage.page+'/'+temp.src,
			method :'post',
		 	onSuccess: function(responseText, responseXML){
				showLesson();
			},
			onComplete: function(){
				
			},
			onFailure: function(xhr){
				alert("failure");
			}
		});
		form.send();
	return false;
}

function nextl(val){
	var perpage = {
			page : parseInt($(document.forms['viewperpage']).perpage.value)
		}
	var temp = {
			src : $(document.forms['search']).src.value
		}
	var source,next;
	source = limit.start;
	limit.start = source+perpage.page;
	var myRequest = new Request({
		url: '<?php echo base_url()."dash/lesson_show/"?>'+'/'+limit.start+'/'+perpage.page+'/'+temp.src,
		method: 'post',
		onSuccess : function(responseText){
			$('lesson_show').innerHTML = responseText;
		}
	}).send();
}

function prevl(){
	var perpage = {
			page : parseInt($(document.forms['viewperpage']).perpage.value)
		}
	var temp = {
			src : $(document.forms['search']).src.value
		}
	var source,next;
	source = limit.start;
	if(source>=perpage.page){
		limit.start = source-perpage.page;
		var myRequest = new Request({
			url: '<?php echo base_url()."dash/lesson_show/"?>'+'/'+limit.start+'/'+perpage.page+'/'+temp.src,
			method: 'post',
			onSuccess : function(responseText){
				$('lesson_show').innerHTML = responseText;
			}
		}).send();
	} else {
		return false;
	}
}

function clear() {
	$('search').reset();
	showLesson();
}

window.addEvent('domready',function(){
    showLesson();
    //cekSubject();
});
</script>
<div class="margin-top-10">

<table width="100%" height="500" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="left" valign="top" width="<?php echo $w_lpanel_content?>"><?php echo $left?></td>
    <td align="center" valign="top" width="<?php echo $w_rpanel_content?>"><?php echo $right?></td>
  </tr>
</table>
</div>